package com.common.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class AccessFileProperties {

	private static final String PATH="/message.properties";

	private static Map<String,String> properties=new HashMap<String, String>();
	static{
		Logger log = LoggerFactory.getLogger(AccessFileProperties.class);
		Properties propertie=new Properties();
		InputStream in=null;
		try {
			in =AccessFileProperties.class.getResourceAsStream(PATH);
			propertie.load(in);
			Set set=propertie.keySet();
			for (Object object : set) {
				String key=StrUtils.objectToStr(object);
				String value=StrUtils.objectToStr(StrUtils.toUTF8(propertie.getProperty(key, "属性文件没有配置此属性错误信息！")));
				properties.put(key, value);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.error("读取消息属性配置文件出错:配置文件名称："+PATH+",错误信息："+e);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.error("加载load消息属性配置文件出错:配置文件名称："+PATH+",错误信息："+e);
		}finally{
			try {
				if(in!=null)
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				log.error("关闭属性配件流出错:配置文件名称："+PATH+",错误信息："+e);
			}
		}
	}
	public static Map<String, String> getProperties() {
		return properties;
	}
	public static void setProperties(Map<String, String> properties) {
		AccessFileProperties.properties = properties;
	}
}
